use std::{
    fmt,
    future::Future,
    pin::Pin,
    task::{Context, Poll},
};

pub(crate) enum SignalKind {
    Int,
    Term,
    Quit,
}

impl fmt::Display for SignalKind {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(match self {
            SignalKind::Int => "SIGINT",
            SignalKind::Term => "SIGTERM",
            SignalKind::Quit => "SIGQUIT",
        })
    }
}

pub(crate) struct Signals {
    #[cfg(not(unix))]
    signals: futures_core::future::BoxFuture<'static, std::io::Result<()>>,
}

impl Signals {
    pub(crate) fn new() -> Self {
        Signals {
            signals: Box::pin(tiny_r_rt::signal::ctrl_c()),
        }
    }
}

impl Future for Signals {
    type Output = SignalKind;
    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        self.signals.as_mut().poll(cx).map(|_| SignalKind::Int)
    }
}

#[test]
fn test_display() {
    println!("{}", SignalKind::Int)
}
